CREATE    PROC SP_SAVE_AMKOR_LOT_STATUS (
	@CUSTOMER_NO			VARCHAR (10),
	@CUSTOMER_NAME			VARCHAR (25),
	@FACTORY_CODE			VARCHAR (10),
	@FACTORY_FULL_NAME		VARCHAR (25),
	@CURRENT_PLANT			VARCHAR (10),
	@BUSINESS_CODE			VARCHAR (10),
	@PKG_DIM_LEAD_DESC		VARCHAR (50),
	@PACKAGE_DESC			VARCHAR (50),
	@PACKAGE_CODE			VARCHAR (10),
	@DIMENSION			VARCHAR (10), 
	@LEAD_COUNT			VARCHAR (10),
	@PACKAGE_FAMILY_CODE		VARCHAR (10),
	@PACKAGE_FAMILY_CODE_DESC       VARCHAR (50),
	@CUST_SOURCE_DEVICE		VARCHAR (50),
	@CUST_TARGET_DEVICE		VARCHAR (50), 
	@CUST_LOT_NO			VARCHAR (50),
	@FACTORY_LOT_NO			VARCHAR (50),
	@CUST_WAFER_RUN_NO		VARCHAR (10),
	@CUST_PO_NO			VARCHAR (25),
	@DIEBANK_FLAG			VARCHAR (10), 
	@CURRENT_OPERATION_CODE		VARCHAR (10),
	@CURRENT_OPERATION_CODE_DESC    VARCHAR (50),
	@CURRENT_OPERATION_FULL_DESC    VARCHAR (50),
	@LOT_PRIORITY			VARCHAR (25),
	@LOT_HANDLING_CODE		VARCHAR (10), 
	@LOT_HOLD_STATUS		VARCHAR (10),
	@LOT_HOLD_CODE			VARCHAR (10),
	@LOT_HOLD_CODE_DESC		VARCHAR (50),
	@LOT_HOLD_DATE			VARCHAR (50),
	@LOT_SHIPTO_CODE		VARCHAR (25), 
	@DATE_CODE			VARCHAR (25),
	@TRACE_CODE			VARCHAR (25),
	@MISCELLANEOUS_FIELD		VARCHAR (25),
	@CUST_INVOICE_NO		VARCHAR (25),
	@COMMERCIAL_INVOICE		VARCHAR (25), 
	@ACTUAL_AIRPORT_DATE		VARCHAR (50),
	@RECEIPT_DATE			VARCHAR (50),
	@RELEASE_DATE			VARCHAR (50),
	@SCHEDULE_DATE			VARCHAR (50),
	@ASSEMBLY_START_DATE		VARCHAR (50), 
	@PROJ_ASSY_OUTDATE		VARCHAR (50),
	@ACTUAL_ASSYOUT_DATE		VARCHAR (50),
	@TEST_START_DATE		VARCHAR (50),
	@PROJ_TESTOUT_DATE		VARCHAR (50),
	@ACTUAL_TESTOUT_DATE		VARCHAR (50), 
	@FGI_DATE			VARCHAR (50),
	@PLANNED_SHIPBACK_DATE		VARCHAR (50),
	@REVISED_PLANNED_SHIPDATE	VARCHAR (50),
	@FIRM_SHIPBACK_DATE		VARCHAR (50),
	@REVISED_PROJECTED_SHIPDATE	VARCHAR (50), 
	@CURRENT_PROJECTED_SHIPDATE	VARCHAR (50),
	@ACTUAL_SHIPDATE		VARCHAR (50),
	@CURRENT_PROCESS_DATE		VARCHAR (50),
	@INTRANSIT_QTY			VARCHAR (50),
	@RECEIPT_QTY			VARCHAR (50), 
	@BANK_QTY			VARCHAR (50),
	@SCHEDULE_QTY			VARCHAR (50),
	@ASSEMBLY_START_QTY		VARCHAR (50),
	@TEST_START_QTY			VARCHAR (50),
	@WIP_CURRENT_QTY_LOT		VARCHAR (50), 
	@CURRENT_QTY			VARCHAR (50),
	@SHIP_QTY			VARCHAR (50), 
	@CUST_DATA01			VARCHAR (50),
	@CUST_DATA01_ATTRIBUTE		VARCHAR (50),
	@CUST_DATA02			VARCHAR (50),
	@CUST_DATA02_ATTRIBUTE		VARCHAR (50),
	@CURRENT_PROCESS_CTDAYS		VARCHAR (10),
	@ASSY_CTDAYS			VARCHAR (10),
	@TEST_CTDAYS			VARCHAR (10),
	@CURRENT_DATE			VARCHAR (10) )
        
	AS
	BEGIN
		DECLARE @DATE_TIME DATETIME 
     		DECLARE @START_DATE DATETIME 
     		DECLARE @END_DATE DATETIME 
		DECLARE @TIME_STAMP DATETIME 
     		DECLARE @TEMP_VARCHAR VARCHAR(20)
		
		SET @TEMP_VARCHAR = CONVERT(VARCHAR, CURRENT_TIMESTAMP, 101)+' 12:00AM'
     		SET @START_DATE = CONVERT(VARCHAR (50), @TEMP_VARCHAR)
     		SET @TEMP_VARCHAR = NULL
     		SET @TEMP_VARCHAR = CONVERT(VARCHAR, CURRENT_TIMESTAMP, 101)+' 11:59PM' 
     		SET @END_DATE = CONVERT(VARCHAR (50), @TEMP_VARCHAR)
		
		SELECT @TIME_STAMP = MAX(TIMESTAMP) FROM AMKOR_LOT_STATUS_TABLE WHERE TIMESTAMP BETWEEN @START_DATE AND @END_DATE
		
		INSERT INTO AMKOR_LOT_STATUS_TABLE(CUSTOMER_NO,CUSTOMER_NAME,FACTORY_CODE,FACTORY_FULL_NAME,CURRENT_PLANT,BUSINESS_CODE,PKG_DIM_LEAD_DESC,PACKAGE_DESC,PACKAGE_CODE,DIMENSION,LEAD_COUNT,PACKAGE_FAMILY_CODE,PACKAGE_FAMILY_CODE_DESC,        
				CUST_SOURCE_DEVICE,CUST_TARGET_DEVICE,CUST_LOT_NO,FACTORY_LOT_NO,CUST_WAFER_RUN_NO,CUST_PO_NO,DIEBANK_FLAG,CURRENT_OPERATION_CODE,CURRENT_OPERATION_CODE_DESC,CURRENT_OPERATION_FULL_DESC,LOT_PRIORITY,LOT_HANDLING_CODE,LOT_HOLD_STATUS,
				LOT_HOLD_CODE,LOT_HOLD_CODE_DESC,LOT_HOLD_DATE,LOT_SHIPTO_CODE,DATE_CODE,TRACE_CODE,MISCELLANEOUS_FIELD,CUST_INVOICE_NO,COMMERCIAL_INVOICE,ACTUAL_AIRPORT_DATE,RECEIPT_DATE,RELEASE_DATE,SCHEDULE_DATE,ASSEMBLY_START_DATE,PROJ_ASSY_OUTDATE,
				ACTUAL_ASSYOUT_DATE,TEST_START_DATE,PROJ_TESTOUT_DATE,ACTUAL_TESTOUT_DATE,FGI_DATE,PLANNED_SHIPBACK_DATE,REVISED_PLANNED_SHIPDATE,FIRM_SHIPBACK_DATE,REVISED_PROJECTED_SHIPDATE,CURRENT_PROJECTED_SHIPDATE,ACTUAL_SHIPDATE,CURRENT_PROCESS_DATE,
				INTRANSIT_QTY,RECEIPT_QTY,BANK_QTY,SCHEDULE_QTY,ASSEMBLY_START_QTY,TEST_START_QTY,WIP_CURRENT_QTY_LOT,CURRENT_QTY,SHIP_QTY,CUST_DATA01,CUST_DATA01_ATTRIBUTE,CUST_DATA02,CUST_DATA02_ATTRIBUTE,CURRENT_PROCESS_CTDAYS,ASSY_CTDAYS,TEST_CTDAYS,TIMESTAMP)		
				VALUES(@CUSTOMER_NO,@CUSTOMER_NAME,@FACTORY_CODE,@FACTORY_FULL_NAME,@CURRENT_PLANT,@BUSINESS_CODE,@PKG_DIM_LEAD_DESC,@PACKAGE_DESC,@PACKAGE_CODE,@DIMENSION,@LEAD_COUNT,@PACKAGE_FAMILY_CODE,@PACKAGE_FAMILY_CODE_DESC,        
				@CUST_SOURCE_DEVICE,@CUST_TARGET_DEVICE,@CUST_LOT_NO,@FACTORY_LOT_NO,@CUST_WAFER_RUN_NO,@CUST_PO_NO,@DIEBANK_FLAG,@CURRENT_OPERATION_CODE,@CURRENT_OPERATION_CODE_DESC,@CURRENT_OPERATION_FULL_DESC,@LOT_PRIORITY,@LOT_HANDLING_CODE,@LOT_HOLD_STATUS,
				@LOT_HOLD_CODE,@LOT_HOLD_CODE_DESC,@LOT_HOLD_DATE,@LOT_SHIPTO_CODE,@DATE_CODE,@TRACE_CODE,@MISCELLANEOUS_FIELD,@CUST_INVOICE_NO,@COMMERCIAL_INVOICE,@ACTUAL_AIRPORT_DATE,@RECEIPT_DATE,@RELEASE_DATE,@SCHEDULE_DATE,@ASSEMBLY_START_DATE,@PROJ_ASSY_OUTDATE,
				@ACTUAL_ASSYOUT_DATE,@TEST_START_DATE,@PROJ_TESTOUT_DATE,@ACTUAL_TESTOUT_DATE,@FGI_DATE,@PLANNED_SHIPBACK_DATE,@REVISED_PLANNED_SHIPDATE,@FIRM_SHIPBACK_DATE,@REVISED_PROJECTED_SHIPDATE,@CURRENT_PROJECTED_SHIPDATE,@ACTUAL_SHIPDATE,@CURRENT_PROCESS_DATE,
				@INTRANSIT_QTY,@RECEIPT_QTY,@BANK_QTY,@SCHEDULE_QTY,@ASSEMBLY_START_QTY,@TEST_START_QTY,@WIP_CURRENT_QTY_LOT,@CURRENT_QTY,@SHIP_QTY,@CUST_DATA01,@CUST_DATA01_ATTRIBUTE,@CUST_DATA02,@CUST_DATA02_ATTRIBUTE,@CURRENT_PROCESS_CTDAYS,@ASSY_CTDAYS,@TEST_CTDAYS,CURRENT_TIMESTAMP)		


		INSERT INTO AMKOR_LOT_STATUS_HISTORY_TABLE(CUSTOMER_NO,CUSTOMER_NAME,FACTORY_CODE,FACTORY_FULL_NAME,CURRENT_PLANT,BUSINESS_CODE,PKG_DIM_LEAD_DESC,PACKAGE_DESC,PACKAGE_CODE,DIMENSION,LEAD_COUNT,PACKAGE_FAMILY_CODE,PACKAGE_FAMILY_CODE_DESC,        
				CUST_SOURCE_DEVICE,CUST_TARGET_DEVICE,CUST_LOT_NO,FACTORY_LOT_NO,CUST_WAFER_RUN_NO,CUST_PO_NO,DIEBANK_FLAG,CURRENT_OPERATION_CODE,CURRENT_OPERATION_CODE_DESC,CURRENT_OPERATION_FULL_DESC,LOT_PRIORITY,LOT_HANDLING_CODE,LOT_HOLD_STATUS,
				LOT_HOLD_CODE,LOT_HOLD_CODE_DESC,LOT_HOLD_DATE,LOT_SHIPTO_CODE,DATE_CODE,TRACE_CODE,MISCELLANEOUS_FIELD,CUST_INVOICE_NO,COMMERCIAL_INVOICE,ACTUAL_AIRPORT_DATE,RECEIPT_DATE,RELEASE_DATE,SCHEDULE_DATE,ASSEMBLY_START_DATE,PROJ_ASSY_OUTDATE,
				ACTUAL_ASSYOUT_DATE,TEST_START_DATE,PROJ_TESTOUT_DATE,ACTUAL_TESTOUT_DATE,FGI_DATE,PLANNED_SHIPBACK_DATE,REVISED_PLANNED_SHIPDATE,FIRM_SHIPBACK_DATE,REVISED_PROJECTED_SHIPDATE,CURRENT_PROJECTED_SHIPDATE,ACTUAL_SHIPDATE,CURRENT_PROCESS_DATE,
				INTRANSIT_QTY,RECEIPT_QTY,BANK_QTY,SCHEDULE_QTY,ASSEMBLY_START_QTY,TEST_START_QTY,WIP_CURRENT_QTY_LOT,CURRENT_QTY,SHIP_QTY,CUST_DATA01,CUST_DATA01_ATTRIBUTE,CUST_DATA02,CUST_DATA02_ATTRIBUTE,CURRENT_PROCESS_CTDAYS,ASSY_CTDAYS,TEST_CTDAYS,ADAPTOR_DATE,TIMESTAMP)		
				VALUES(@CUSTOMER_NO,@CUSTOMER_NAME,@FACTORY_CODE,@FACTORY_FULL_NAME,@CURRENT_PLANT,@BUSINESS_CODE,@PKG_DIM_LEAD_DESC,@PACKAGE_DESC,@PACKAGE_CODE,@DIMENSION,@LEAD_COUNT,@PACKAGE_FAMILY_CODE,@PACKAGE_FAMILY_CODE_DESC,        
				@CUST_SOURCE_DEVICE,@CUST_TARGET_DEVICE,@CUST_LOT_NO,@FACTORY_LOT_NO,@CUST_WAFER_RUN_NO,@CUST_PO_NO,@DIEBANK_FLAG,@CURRENT_OPERATION_CODE,@CURRENT_OPERATION_CODE_DESC,@CURRENT_OPERATION_FULL_DESC,@LOT_PRIORITY,@LOT_HANDLING_CODE,@LOT_HOLD_STATUS,
				@LOT_HOLD_CODE,@LOT_HOLD_CODE_DESC,@LOT_HOLD_DATE,@LOT_SHIPTO_CODE,@DATE_CODE,@TRACE_CODE,@MISCELLANEOUS_FIELD,@CUST_INVOICE_NO,@COMMERCIAL_INVOICE,@ACTUAL_AIRPORT_DATE,@RECEIPT_DATE,@RELEASE_DATE,@SCHEDULE_DATE,@ASSEMBLY_START_DATE,@PROJ_ASSY_OUTDATE,
				@ACTUAL_ASSYOUT_DATE,@TEST_START_DATE,@PROJ_TESTOUT_DATE,@ACTUAL_TESTOUT_DATE,@FGI_DATE,@PLANNED_SHIPBACK_DATE,@REVISED_PLANNED_SHIPDATE,@FIRM_SHIPBACK_DATE,@REVISED_PROJECTED_SHIPDATE,@CURRENT_PROJECTED_SHIPDATE,@ACTUAL_SHIPDATE,@CURRENT_PROCESS_DATE,
				@INTRANSIT_QTY,@RECEIPT_QTY,@BANK_QTY,@SCHEDULE_QTY,@ASSEMBLY_START_QTY,@TEST_START_QTY,@WIP_CURRENT_QTY_LOT,@CURRENT_QTY,@SHIP_QTY,@CUST_DATA01,@CUST_DATA01_ATTRIBUTE,@CUST_DATA02,@CUST_DATA02_ATTRIBUTE,@CURRENT_PROCESS_CTDAYS,@ASSY_CTDAYS,@TEST_CTDAYS,@CURRENT_DATE,CURRENT_TIMESTAMP)		
	END
